import { queryMeetingRoomList } from '../services/MeetingRoomApi';

export default {
  namespace: 'meetingRoomList',

  state: {
    loading: false,
    list: [],
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      yield put({
        type: 'changeLoading',
        payload: true,
      });
      const response = yield call(queryMeetingRoomList, payload);
      yield put({
        type: 'loadQuery',
        payload: response.data,
      });
      yield put({
        type: 'changeLoading',
        payload: false,
      });
    },
  },

  reducers: {
    changeLoading(state, { payload }) {
      return {
        ...state,
        loading: payload,
      };
    },
    loadQuery(state, { payload }) {
      return {
        ...state,
        list: payload,
      };
    },
  },
};
